home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc2 / since.lha / Since.rexx < prev   
OS/2 REXX Batch file  |  1996-05-19  |  8KB  |  294 lines

  1.  
  2. /*
  3.  
  4. Shows how many days/weeks/months/years have past since certain events
  5. occurred.  (or until coming future events.)
  6.  
  7. Your personalized list might look something like:
  8. > Dentist visit...  8.0 months ago.
  9. > Eye examine..... 11.4 months ago.
  10. > Physical........  5.2 months ago.
  11. > Pay Raise.......  6.6 months ago.
  12. > Marriage........  9.4 years ago.
  13. > My Retirement... 23.1 years from now.
  14. > Oil change...... 33.0 days ago.
  15. > Next Birthday...  1.9 months from now.
  16. > End of Century..  3.6 years from now.
  17. > Christmas.......  7.8 months from now.
  18. > Taxes Due....... 11.0 months from now.
  19.  
  20. You make a config file called s:since.dat that looks like:
  21. > 12-May-1995 Dentist visit
  22. > 15-Aug-1995 Eye examine
  23. > 20-Nov-1995 Physical
  24. > 08-Jan-1996 Oil change
  25.  
  26. "Since" uses options like:
  27. > SHOW                  (Show the output.)
  28. > EDIT                  (Edit any 1 line of the config file.)
  29. > HELP                  (Show a help-screen.)
  30. > ADD                   (Add 1 line to the config file.)
  31. > CONFIG=s:since.dat    (Use this config file.)
  32. > FIND=taxes            (Find and display lines contain this word.)
  33.  
  34. All dates in s:since.dat config must occur between 01-Jan-1978 and 31-Dec-2100.
  35.  
  36. Installation:
  37.    Copy since.rexx TO rexx:
  38.    Copy since.dat  TO s:
  39.    Create a DOS alias like:   Alias since   rx rexx:since.rexx SHOW
  40.  
  41. $VER: Since.rexx v1.0 19-May-96 by Bill Beogelein
  42.    First public release version.  (to aminet)
  43.  
  44. $VER: Since.rexx v0.9 29-Apr-96 by Bill Beogelein
  45.    Beta-test version.
  46.  
  47. Author Info:
  48.    Bill Beogelein
  49.    Box 530441
  50.    Livonia, MI 48153 USA
  51.    SysOp of The Amiga ShareWare HeadQuarters BBS 28k8 1-810-473-2020
  52.    Fido: 1:2410/207,  Internet: ag775@detroit.freenet.org
  53.  
  54. Future Plans:
  55.    Send suggestions for new features (and bug reports) to the address above.
  56.    Re-write in C.
  57.    Also re-save comments also.
  58.    Also allow (and hide) comments at the ends of lines.
  59.    If bad date found, allow editing or removal.
  60.    Add NoFIND=string option.
  61.    If passed a valid date, show since/ago days.
  62.  
  63. Ignore:
  64.    lha u dh6:a/6.6/since.lha Rexx:since.rexx up:since.dat up:since.readme
  65.  
  66. *********************** End of docs *******************************/
  67.  
  68. call Init()
  69.  
  70. /************** Top of user-definable variables ******************/
  71.  
  72. def_config = "s:Since.dat"    /* Use this default config file if none is specified */
  73.  
  74. dy_limit = 90     /* After x days,   display using "weeks"  */
  75. wk_limit = 12     /* After x weeks,  display using "months" */
  76. mo_limit = 10     /* After x months, display using "years"  */
  77.  
  78. width = 1         /* Width of "123.45 date" decimal places (Default==1) */
  79.  
  80. /************** End of user-definable variables ******************/
  81.  
  82. parse arg opts
  83. o_add   = GetSwitch(opts, "ADD"  , 0)
  84. o_edit  = GetSwitch(opts, "EDIT" , 0)
  85. o_show  = GetSwitch(opts, "SHOW" , 0)
  86. o_help  = GetSwitch(opts, "HELP" , 0)
  87.  
  88. o_config = GetKeyWrd(opts, "CONFIG=", def_config)
  89. o_find   = GetKeyWrd(opts, "FIND="  , "-")
  90. o_find   = upper(o_find)
  91.  
  92. if(o_help) then
  93. do
  94.    say ""
  95.    address command "Version rexx:Since.rexx FULL FILE"
  96.    say ""
  97.  
  98.    say " ADD            : Add new dates and text."
  99.    say " EDIT           : Edit dates and text."
  100.    say " SHOW           : Show dates."
  101.    say " HELP           : Displays this help-screen."
  102.    say ""
  103.    say " FIND=string    : Only display lines containing this string."
  104.    say " CONFIG=s:fName : Use this config file." LF
  105.  
  106.    say " Format used in config is: 20-May-1997 The String To Display." LF
  107.    exit
  108. end
  109.  
  110. if(o_show | o_find~="-") then call ShowDates()
  111. if(o_edit) then call Edit()
  112. if(o_add ) then call Add()
  113.  
  114. exit  /*** End of main ***/
  115.  
  116. Add:
  117.    do i=1 to 999
  118.       mode='Writing'; if(exists(o_config)) then mode='Appending'
  119.       say "" mode "new events to" o_config "..." LF
  120.       say " Format is: 20-May-1997 The String To Display."
  121.       call writeCH(STDOUT, " New Event: ")
  122.       ans = readLN(STDIN)
  123.       if(ans=="") then
  124.       do
  125.          say LF "*** Ending new additions." BELL LF
  126.          return
  127.       end
  128.       if(open(fp, o_config, mode)) then
  129.       do
  130.          call writeLN(fp, ans)
  131.          call close(fp)
  132.       end
  133.       else
  134.          say LF "*** Rexx:since.rexx can't open" o_config "for" mode BELL LF
  135.    end
  136. return
  137.  
  138. Load:
  139.    libname="rexxsupport.library"
  140.    if( ~show('LIBRARIES', libname) ) then
  141.       if( ~addlib(libname, 0, -30) ) then
  142.       do
  143.          say LF "*** Rexx:Since.rexx can't open libs:" || libname BELL LF
  144.          exit
  145.       end      /* Leave loaded */
  146.  
  147.    if(open(fp, o_config, 'READ')) then
  148.    do
  149.       configCount=0
  150.       maxWidth=2
  151.       do i=1 to 9999
  152.          buf = strip(readLN(fp))
  153.          if(eof(fp))             then leave
  154.          if(buf == "")           then iterate
  155.          if(left(buf, 1) == ';') then iterate
  156.          configCount= configCount+1
  157.          config.configCount = buf
  158.          /* say aaa buf zzz */
  159.          w= length(buf)
  160.          if(w>maxWidth) then maxWidth=w
  161.  
  162.          dt= left(buf,2)            /* 12345678901 */
  163.          yr= substr(buf,8,4)        /* 12-Apr-1996 */
  164.          if(yr<1978 | yr>2099 | dt<1 | dt>31) then
  165.          do
  166.             say LF "*** Rexx:Since.rexx detects date outside of" LF "*** legal range (1978-2100) in" o_config "..." LF buf LF BELL
  167.             exit
  168.          end
  169.       end
  170.       call close(fp)
  171.    end
  172.    else
  173.    do
  174.       say LF "*** Rexx:Since.rexx can't open" o_config "for reading." BELL LF
  175.       exit
  176.    end
  177. return
  178.  
  179. Save:
  180.    if(open(fp, o_config, 'WRITE')) then
  181.    do
  182.       say LF "Saving to" o_config "..."
  183.       do i=1 to configCount
  184.          call writeLN(fp, config.i)
  185.          say right(i || ")" ,3) config.i
  186.       end
  187.       call close(fp)
  188.    end
  189.    else
  190.    do
  191.       say LF "*** Rexx:Since.rexx can't open" o_config "for writing." BELL LF
  192.       exit
  193.    end
  194. return
  195.  
  196. Edit:
  197.    call ShowDates()
  198.    call writeCH(STDOUT, "Edit which: ")
  199.    ans = readLN(STDIN)
  200.    if(ans=="") then
  201.    do
  202.       say LF "*** Edit aborted." BELL LF
  203.       return
  204.    end
  205.  
  206.    say LF "Old:" config.ans
  207.    call writeCH(STDOUT, " New: ")
  208.    new = strip(readLN(STDIN))
  209.    if(new == "") then
  210.    do
  211.       say LF "*** Edit aborted." BELL LF
  212.       return
  213.    end
  214.    call writeCH(STDOUT, " Save" new "([y]es/[N]o)? ")
  215.    confirm = left(upper(readLN(STDIN)),1)
  216.    if(confirm=='Y') then
  217.    do
  218.       config.ans = new
  219.       call Save()
  220.    end
  221.    else
  222.       say LF "*** Edit aborted." BELL LF
  223. return
  224.  
  225. ShowDates:
  226.    call Load()
  227.  
  228.    do i=1 to configCount
  229.       diff= date('INTERNAL') - Date2Int(word(config.i,1))
  230.       if(o_edit) then
  231.          counter= right(i || ")", 3)
  232.       else
  233.          counter=""
  234.       if(pos(o_find,upper(config.i))>0) then
  235.          say counter left(config.i, maxWidth+2, '.') || Shorten(diff)
  236.    end
  237. return
  238.  
  239. GetSwitch:  PROCEDURE   EXPOSE opts
  240.    parse arg opts, str, def
  241.    w=find(upper(opts), upper(str))
  242.    if(w<1) then return def
  243.    opts=delword(opts, w, 1)
  244. return ~(def)        /*** End of GetSwitch ***/
  245.  
  246. GetKeyWrd:     PROCEDURE   EXPOSE opts
  247.    parse arg opts, str, def
  248.    p=pos(upper(str), upper(opts))
  249.    if(p<1) then return def
  250.    len=length(str)
  251.    s=word(substr(opts, p+len),1)
  252.    opts=delstr(opts, p, len+length(s)+1)
  253. return s             /*** End of GetKeyWrd ***/
  254.  
  255. Shorten: PROCEDURE EXPOSE c30 c365 width    dy_limit wk_limit mo_limit
  256.    parse arg days    /* Convert days into "xx.x yrs/mos/wks/etc" */
  257.    past= "ago."
  258.    if(days<0) then
  259.    do
  260.       past="from now."
  261.       days= days*(-1)
  262.    end
  263.                                str= right(trunc(days      , width), width+4) "days"
  264.    if(days >     dy_limit) then str= right(trunc(days/7   , width), width+4) "weeks"
  265.    if(days > 7  *wk_limit) then str= right(trunc(days/c30 , width), width+4) "months"
  266.    if(days > c30*mo_limit) then str= right(trunc(days/c365, width), width+4) "years"
  267. return str past
  268.  
  269. Date2Int: PROCEDURE    /* Convert 31-Dec-1995 into internal date */
  270.    parse arg dat
  271.  
  272.    dat= upper(dat)
  273.    dt = left(dat,2)
  274.    mo = substr(dat,4,3)
  275.    yr = right(dat,4)     /* if(yr<79) then yr=yr+2000; else yr=yr+1900 */
  276.  
  277.    p = pos(mo, "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC")
  278.    p = (p%3)+1
  279.    mo= right(p, 2, '0')
  280.  
  281.    sort= yr || mo || dt   /* 19941231 */
  282. return date('INTERNAL', sort, 'SORTED')
  283.  
  284. Init:
  285.    LF   = '0a'x
  286.    BELL = '07'x
  287.  
  288.    c365 = 365.25
  289.    c30  = c365/12     /* Avg # of days in 1 month */
  290. return
  291.  
  292. /*** End of Rexx:Since.rexx by Bill Beogelein 810-473-2020 ***/
  293.  
  294.